package com.luo.test


import scala.io.Source

object Read {



  def main(args: Array[String]) {
    println("程序开始")
    val source = Source.fromFile("f://aaa.log", "UTF-8")
    val lineIterator = source.getLines

    val buf = new StringBuilder;
    val buf1 = new StringBuilder;
    val buf2 = new StringBuilder;

    for(lines <- source.getLines) {
      if(containsIs("[com",lines.toString)) {
        val text = lines.toString.substring(lines.toString.indexOf("[com") + 1, lines.toString.indexOf("]", lines.toString.indexOf("[com")))
        val times = lines.split(" ")(2)

        buf2.append(times).append(",")
        buf1.append(text).append("!")
      }
    }
    val timeArray=buf2.toString().split(",")
    val actionList=buf1.toString().split("!").toList
    val actionListDistinct=buf1.toString().split("!").toList.distinct
    var sumCount=0
    for(action <- actionListDistinct) {
      var sum=0;

        for(i <- 0 until actionList.length){

           if(actionList(i)==action){
             sum+=1
             sumCount += timeArray(i).toInt

           }

        }
       println("请求的方法是:"+action+"------------请求的次数是"+sum+"次-------平均时长："+sumCount/sum+"ms")

    }
    println("程序结束")
    source.close
  }


  def containsIs(foo:String,lines:String) ={
    lines.contains(foo)
  }




}
